package controller;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JTable;

import model.kwalificatiebeheer.Kerntaak;
import model.kwalificatiebeheer.KwalificatieDossier;

import view.KerntaakPanel;
import view.KwalificatieDossierPanel;

public class KerntaakTableActions implements MouseListener {
	private KwalificatieDossierPanel sender;
	private JTable kttable;
	
	public KerntaakTableActions(KwalificatieDossierPanel sender, JTable kttable) {
		this.sender = sender;
		this.kttable = kttable;
	}
	
	@Override
	public void mousePressed(MouseEvent e) {
		if(e.getClickCount() == 1){
			Kerntaak kt = ktTableSelect();
		} else if(e.getClickCount() == 2) {
			Kerntaak kt = ktTableSelect();
			JFrame ktFrame = new JFrame();
			ktFrame.setTitle("Kerntaak: "+kt.getTitle());
			ImageIcon icon = new ImageIcon(this.getClass().getResource("../resources/favicon.png"));
			ktFrame.setIconImage(icon.getImage());
			ktFrame.getContentPane().add(new KerntaakPanel(kt));
			ktFrame.setSize(700, 300);
			ktFrame.setVisible(true);				
			ktFrame.setLocationRelativeTo(null);
		}
	}
	
	public Kerntaak ktTableSelect(){		
		KwalificatieDossier kd = sender.getActive();
		ArrayList<Kerntaak> list = new ArrayList<Kerntaak>(kd.getKerntaken());
		Kerntaak kt = list.get(kttable.getSelectedRow());
		sender.setActiveKt(kt);
		return kt;
	}
	
	@Override
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

}
